<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/reset.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/common.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome.min.css">
<!--公共样式结束-->
<!--公共JS开始-->
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.min.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.timer.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/common.js"></script>
<!--公共JS结束-->
<!--数据列表插件开始-->
<link href="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.css" rel="stylesheet" type="text/css" />
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.ui.position.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.js"></script>
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Css/etgrid.css">
<script src="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Js/etgrid.js"></script>
<!--数据列表插件结束-->
<style type="text/css">
	body {
		overflow:hidden;
	}
	.table_box {
	}
</style>
</head>

<body>
	<div class="page_header">
	<div class="table_tool">
		<ul class="clearfix">		
			<li class="openwin btn" etitle="新增地址" eheight="400px" ewidth="600px" ehref="{:U('Address/add')}" id="Address_add"><i class="icon-plus"></i> 新增地址</li>
		</ul>
	</div>
	
	
	 	<div class="search_box">
	 		<php>if(C('ADMIN_ROLE')==session(C('USER_AUTH_ROLE'))){</php>
				所属地区：<span id="areaBox"></span>
			<php>}</php>
			<input type='text' class='form_ele w200' id='keywords' name='keywords'>
			<span id="doSearch" class="doSearch"><i class="icon-search"></i> 搜索</span>
			<span id="doReset" class="doSearch"><i class="icon-search"></i> 重置</span>
		</div>
	
	
	</div>
	<div class="table_box">
	</div>
</body>
<script type="text/javascript">
	var listConfig = {
			gridId : 'memberList',
			blockBox : '.table_box',
			blockBoxHeight : 'window',
			jsonUrl : '__URL__/index',
			where : '',
	 		getWhere : function(){
	 			return getwheres();
			},
			
			widthType : 'tdw', //thw-标题标准宽度、tdw-数据单元标准宽度、auto-随数据单元宽度
			pageNum : 10,
			nowPage : 1,
			orderName : "addtime",
			orderDirection : "desc",
			dataContextMenuOpen: true, //是否开启数据行右键菜单
			dataContextMenu: function(){
				$.contextMenu({
					selector: '.et_tbody tr',
					items: {
						"edit": {
							name: "修改", 
							icon: "edit",
							callback: function(key, options) {
								var href   = "{:U('Address/edit')}&id="+$(this).attr('rowid');
								var width  = '600px';
								var height = '350px';
								var title  = '修改地址';
								openDialog('Address_edit',href,width,height,title);
							}
						},
						"delete": {
							name: "删除", 
							icon: "edit",
							callback: function(key, options) {
								//var title =  $(this).children('td[fieldname="title"]').html();
								
								var id  = $(this).attr('rowid');
								var msg = '确认删除该地址吗？';

								windowApi.lhgdialog.confirm(msg, function(){	
									$.post("{:U('Address/del')}",{id:id},function(data){
										$('.et_tfoot .page_refresh').click(); //刷新加载
									});
								},function(){return;});
							}
						}
					}
				});
			},
			colModel : [
				{
					display : 'checkbox',
					name : 'id',
					sortable : false,
					myclass : 'center',
					edit : false
				},
				{
					display : '城市地址',
					name : 'ssxadd',
					sortable : true,
					myclass : 'center',
					edit : true,
				},
				{
					display : '地址标签',
					name : 'tags',
					sortable : true,
					myclass : 'center',
					edit : true,
				},
				/*
				{
					display : '关键字',
					name : 'keywords',
					sortable : true,
					myclass : 'center',
					edit : true
				},*/
				{
					display : '经度',
					name : 'longitude',
					sortable : true,
					myclass : 'center',
					edit : false,
				},
				{
					display : '纬度',
					name : 'latitude',
					sortable : true,
					myclass : 'center',
					edit : false,
				},
				{
					display : '添加时间',
					name : 'addtime',
					sortable : true,
					myclass : 'center',
					edit : false,
				},
			]
		};
	
	//实例化列表
	var tableList = $('.table_box').EtGrid(listConfig);
	
	var linkage_json   = {$dictAddressCN|json_encode} ;
	var linkage_jsonen = {$dictAddressEN|json_encode};
	$(function(){
		//初始值处理
		var did = '';
		if(did!=''){
			$('#areaBox').html(dealInitialarea(did,'',1));
		}else{
			$('#areaBox').html(showLinkagearea(39,2,0));
		}
		$('select[name="area"]').live('change',function(){
			var nowLevel  = parseInt($(this).attr('level'));
			var nextLevel = nowLevel+1;
			var enhtml    = '';
			
			//清除自此以后的select
			$('select[name="area"]').each(function(index, element) {
				if(parseInt($(this).attr('level'))>nowLevel){
					$(this).remove();
				}
			});
			//给英文城市地址赋值
			$('select[name="area"]').each(function(index, element) {				
				var areaid = $(this).val();
				if(linkage_jsonen[areaid]){
					enhtml += linkage_jsonen[areaid][0];
				}
			});
			
			$('#ssxadd').val($('select[name="area"]').find("option:selected").text());
			$('#enssxadd').val(enhtml);
			
			$('input[name="area'+nowLevel+'"]').val($(this).val());
			//显示下一个select
			//$('#areaBox').append(showLinkagearea($(this).val(),nextLevel,0));
		});
	});
	
	$(function(){
		
		$("#doSearch").on("click",function(){			
			byCondition();
		});
		
		$('#doReset').on('click',function(){
			$('#area2').val('');
			$('#area3').val('');
			$('#area4').val('');
			$('#keywords').val('');
		});
		
	});	
	
	//处理初始值
	function dealInitialarea(lid,result,level){
		if(lid){
			$.each(linkage_json , function(i, n){
				if(lid==i){
					result = dealInitialarea(n[1],result,(parseInt(level)-1))+''+showLinkagearea(n[1],level,i);
					return false;
				}
			});
		}
		return result;
	}
	
	//响应select改变事件
	function showLinkagearea(pid,level,nid){
		var html = ''; //最终输出的HTML
		var have = false; //是否有子词典
		html += '<select name="area" id="area'+level+'" level="'+level+'" class="form_ele w100">';
		html += '<option value="0">请选择</option>';
		$.each(linkage_json , function(i, n){
			if(pid==n[1]){
				if(nid==i){
					html +       '<option value="'+i+'" selected>'+n[0]+'</option>';
				}else{
					html += '<option value="'+i+'">'+n[0]+'</option>';
				}
				have = true;
			}
		});
		html += '</select>';
		html += '<input type="hidden" name="area'+level+'"/>';
		
		//没有子词典则此次输出为空
		if(!have){
			html = '';
		}
		return html;
	}
	
	
	
	//获取筛选条件并组成数组
	function getwheres(){
		
		var where  = {};
		
		where.city     = $('#area2').val();
		where.keywords = $('#keywords').val();
		
		return where;
	}

	//发送异步进行搜索
	function byCondition(){
		
		var where = tableList.config.getWhere();
		tableList.config.nowPage = 1;
		tableList.config.where   = where;
		tableList.search();
	}
	
</script>
</html>
